// @ts-ignore
import './index.css'

import {Component} from "react";
import {Breadcrumb, Button, Divider, Layout, Tooltip} from "antd";
import {Redirect, Route, Switch, withRouter} from "react-router-dom";

// import Home from "../../../pages/Home";
import History from "../../../pages/History";
import User from "../../../pages/User";
// import Configuration from "../../../pages/Configuration";

import {getBreadcrumbItems} from "../../../utils/menu.util.tsx";
import Admin from "../../../pages/Configuration/Admin";
import Questionnaire from "../../../pages/Configuration/Questionnaire";
import LazyIcon from "../../Tools/Icon";

const {Content} = Layout;

class CustomContent extends Component<any, any> {

    state = {
        refreshKey: Date.now()
    }

    handleRefresh = () => {
        this.setState({refreshKey: Date.now()})
    }

    render() {
        const {location: {pathname}} = this.props;
        const breadcrumbItems = getBreadcrumbItems(pathname);
        const {refreshKey} = this.state;

        return (
            <>
                <Content className="content">
                    <Breadcrumb className="breadcrumb">
                        {breadcrumbItems}
                    </Breadcrumb>
                    <Divider type="vertical"/>
                    <Tooltip title={"刷新内容"}>
                        <Button type="link" onClick={this.handleRefresh} icon={<LazyIcon iconName={"Retweet"}/>}></Button>
                    </Tooltip>
                    <div className="panel">
                        <Switch key={refreshKey}>
                            {/*<Route path="/dashboard/home" component={Home}/>*/}
                            <Route path="/dashboard/history" component={History}/>
                            <Route path="/dashboard/user" component={User}/>

                            {/* 配置中心 */}
                            <Route path="/dashboard/configuration/admin" component={Admin}/>
                            <Route path="/dashboard/configuration/questionnaire" component={Questionnaire}/>
                            {/*<Route path="/dashboard/configuration" component={Configuration}/>*/}

                            <Redirect to="/dashboard/history"/>
                        </Switch>
                    </div>
                </Content>
            </>
        )
    }
}

export default withRouter(CustomContent);
